package com.cloud.logger.zchain.core.common.threadlocal;

import com.cloud.logger.zchain.core.ChainNode;
import com.cloud.logger.zchain.core.common.entity.AngelaLoggerProjectNode;

/**
 * User: wcy
 * Date: 2017/4/8
 * Time: 16:08
 */
public class LoggerThreadLocal {


    private static final ThreadLocal<ChainNode> currentNode=new ThreadLocal<ChainNode>();

    private static final ThreadLocal<AngelaLoggerProjectNode> zchainProject=new ThreadLocal<AngelaLoggerProjectNode>();

    private static final ThreadLocal<String> nodeId=new ThreadLocal<String>();

    private static final ThreadLocal<String> loggerId = new ThreadLocal<String>();

    private static final ThreadLocal<Long> loggerStartNodeTime = new ThreadLocal<Long>();

    public static void setNodeId(String apiName){
        nodeId.set(apiName);
    }

    public static String getNodeLoggerId() {
        return nodeId.get();
    }

    public static void setLoggerId(String id){
        loggerId.set(id);
    }

    public static String getLoggerId() {
        return loggerId.get();
    }

    public static void setLoggerStartNodeTime(Long currentTime){
        loggerStartNodeTime.set(currentTime);
    }

    public static Long getLoggerStartNodeTime() {
        return loggerStartNodeTime.get();
    }

    public static void setCurrentNode(ChainNode chainNode){
        currentNode.set(chainNode);
    }

    public static ChainNode getCurrentNode(){
        return currentNode.get();
    }

    public static void setZchainProject(AngelaLoggerProjectNode project){
        zchainProject.set(project);
    }

    public static AngelaLoggerProjectNode getCurrentProject(){
        if(zchainProject.get()==null)
            return new AngelaLoggerProjectNode();
        else
            return zchainProject.get();
    }

}